﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Acme.ShopStore.Prctures
{
    public class PrctureAppService : ApplicationService, IPrctureAppService
    {
        public IRepository<Prcture, Guid> _repository;

        public PrctureAppService(IRepository<Prcture, Guid> repository)
        {
            _repository = repository;
        }

        public int PrctureAdd(PrctureDto s)
        {
            throw new NotImplementedException();
        }

        // 上传图片
        public string uploadfile(IFormFile File)
        {
            string rootdir = AppContext.BaseDirectory.Split(@"\bin\")[0];
            string fname = DateTime.Now.ToString("yyyyMMddHHmmssffff") + System.IO.Path.GetExtension(File.FileName);
            var path = rootdir + @"\img\" + fname;
            using (System.IO.FileStream fs = System.IO.File.Create(path))
            {
                File.CopyTo(fs);
                fs.Flush();
            }
            return "http://localhost:8088/" + fname;
        }


        public async Task<PrctureDto> ImgAdd(CreateUpdatePrctureDto dto)
        {
            var img = await _repository.InsertAsync(ObjectMapper.Map<CreateUpdatePrctureDto, Prcture>(dto));
            return ObjectMapper.Map<Prcture, PrctureDto>(img);
        }

    }

}
